<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/struts-tags.tld" prefix="s"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>喜乐康智能家居系统</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
  	<script type="text/javascript">

  		$(function(){
  	  		var nowDate = new Date();
			$("#schedule_time_text_year").text(nowDate.getYear()+1900);	
			$("#schedule_time_text_month").text(nowDate.getMonth()+1);
			$("#schedule_time_text_day").text(nowDate.getDate());
			$("#schedule_time_text_hour").text(nowDate.getHours());
			$("#schedule_time_text_minites").text(nowDate.getMinutes());	

			//如果是场景就只有开启的按钮
			if(idType == 2){
				$(".schedule_open").css("margin-left","100px");	
				$(".schedule_close").css("display","none");	
			}
			if(scheduleType == 1){
				$("#schedule_open_close_button").css("display","block");
				$("#schedule_open_close_phone").css("display","none");
			}else if(scheduleType == 2){
				$("#schedule_open_close_button").css("display","none");
				$("#schedule_open_close_phone").css("display","block");
			}
  	  	})
  		openClose ='-1';
  		function scheduleOpenClose(isOpen){
  			openClose = isOpen;
  			if(isOpen == '1'){
				$(".schedule_open").css("background-image","url('"+evn_Path+"resource/setting_scene_add_list_press.png')");
				$(".schedule_close").css("background-image","url('"+evn_Path+"resource/setting_scene_add_list.png')");
  	  		}else if(isOpen == '0'){
				$(".schedule_open").css("background-image","url('"+evn_Path+"resource/setting_scene_add_list.png')");
				$(".schedule_close").css("background-image","url('"+evn_Path+"resource/setting_scene_add_list_press.png')");
  	  		}
  	  	}

  	  	function pressWeek(weekId){
  	  	  	var week = $("#schedule_week_item"+weekId);
  	  		var isSelect = week.attr("isSelect");
  	  		if(isSelect=='1'){
  	  			week.css("background-image","url('"+evn_Path+"resource/schedule_select.png')");
  	  			week.attr("isSelect","0");
  	  	  	}else if(isSelect=='0'){
  	  			week.css("background-image","url('"+evn_Path+"resource/schedule_select_press.png')");
  	  			week.attr("isSelect","1");
  	  	  	}
  	  		
  	  	}

  	  	function pressTimeUpDown(timeUpDown,timeType,keyUpDown){
			switch(timeType){
				case '1':{
					if(keyUpDown=='down'){

					}else if(keyUpDown=='up'){
						var nowDate = new Date();
						var nowYear = nowDate.getYear()+1900;
						if(timeUpDown == 'down'){
							var year = parseInt($("#schedule_time_text_year").text());
							year++;
							$("#schedule_time_text_year").text(year);
						}else if(timeUpDown == 'up'){
							var year = parseInt($("#schedule_time_text_year").text());
							if(year > nowYear){
								year--;
							}else{
								year = nowYear;
							}
							$("#schedule_time_text_year").text(year);
						}
					}
					break;
				}
				case '2':{
					if(keyUpDown=='down'){

					}else if(keyUpDown=='up'){
						if(timeUpDown == 'down'){
							var month = parseInt($("#schedule_time_text_month").text());
							if(month < 12){
								month++;
							}else{
								month = 1;
							}
							$("#schedule_time_text_month").text(month);
						}else if(timeUpDown == 'up'){
							var month = parseInt($("#schedule_time_text_month").text());
							if(month > 1){
								month--;
							}else{
								month = 12;
							}
							$("#schedule_time_text_month").text(month);
						}
					}
					break;
				}
				case '3':{
					if(keyUpDown=='down'){

					}else if(keyUpDown=='up'){
						var date = new Date($("#schedule_time_text_year").text(),$("#schedule_time_text_month").text(),0);
						var maxDate = date.getDate();
						if(timeUpDown == 'down'){
							var day = parseInt($("#schedule_time_text_day").text());
							if(day < maxDate){
								day++;
							}else{
								day = 1;
							}
							$("#schedule_time_text_day").text(day);
						}else if(timeUpDown == 'up'){
							var day = parseInt($("#schedule_time_text_day").text());
							if(day > 1){
								day--;
							}else{
								day = maxDate;
							}
							$("#schedule_time_text_day").text(day);
						}
					}
					break;
				}
				case '4':{
					if(keyUpDown=='down'){

					}else if(keyUpDown=='up'){
						if(timeUpDown == 'down'){
							var hour = parseInt($("#schedule_time_text_hour").text());
							if(hour < 23){
								hour++;
							}else{
								hour = 0;
							}
							$("#schedule_time_text_hour").text(hour);
						}else if(timeUpDown == 'up'){
							var hour = parseInt($("#schedule_time_text_hour").text());
							if(hour > 0){
								hour--;
							}else{
								hour = 23;
							}
							$("#schedule_time_text_hour").text(hour);
						}
					}
					break;
				}
				case '5':{
					if(keyUpDown=='down'){

					}else if(keyUpDown=='up'){
						if(timeUpDown == 'down'){
							var minites = parseInt($("#schedule_time_text_minites").text());
							if(minites < 59){
								minites++;
							}else{
								minites = 0;
							}
							$("#schedule_time_text_minites").text(minites);
						}else if(timeUpDown == 'up'){
							var minites = parseInt($("#schedule_time_text_minites").text());
							if(minites > 0){
								minites--;
							}else{
								minites = 59;
							}
							$("#schedule_time_text_minites").text(minites);
						}
					}
					break;
				}
			}
  	  	}

  	  	function pressTimeAdd(upDown){
	  	  	if(advancedDeviceId == 0){
				if(upDown=='down'){
					alert("请选择面板！");
				}
				return ;
			}else if(openClose == '-1'){
				if(scheduleType == 1){
					if(upDown=='down'){
						alert("请选择开关！");
					}
					return ;
				}else{
					saveSchedule(upDown);
					
				}
			}else{
				saveSchedule(upDown);
				
			}
  	  	}

  	  	function saveSchedule(upDown){
	  	  	if(upDown=='down'){
				$(".schedule_add_button").css("background-image","url('"+evn_Path+"resource/device_button_press.png')");
			}else if(upDown=='up'){
				$(".schedule_add_button").css("background-image","url('"+evn_Path+"resource/device_button.png')");
				var repeatType = "";
				$(".schedule_week_item").each(function(){
					var isSelected = $(this).attr("isselect");
					if(isSelected == 1){
						repeatType+=$(this).attr("weekId");
						repeatType+=",";
					}
				});
				var executeTimeYear = $("#schedule_time_text_year").text();
				var executeTimeMonth = $("#schedule_time_text_month").text();
				if(executeTimeMonth < 10){
					executeTimeMonth = "0"+executeTimeMonth;
				}
				var executeTimeDay = $("#schedule_time_text_day").text();
				if(executeTimeDay < 10){
					executeTimeDay = "0"+executeTimeDay;
				}
				var executeTimeHour = $("#schedule_time_text_hour").text();
				if(executeTimeHour < 10){
					executeTimeHour = "0"+executeTimeHour;
				}
				var executeTimeMinites = $("#schedule_time_text_minites").text();
				if(executeTimeMinites < 10){
					executeTimeMinites = "0"+executeTimeMinites;
				}
				var executeTime = executeTimeYear+"-"+executeTimeMonth+"-"+executeTimeDay+" "+executeTimeHour+":"+executeTimeMinites+":"+"00";
				var phoneNumber = $("#phoneNumber").val();
				if(scheduleType==2){
					if(phoneNumber==null || phoneNumber.trim()==''){
						alert("手机号码不能为空！");
						return ;
					}else{
						if(!(/^1[3|4|5|8][0-9]\d{8}$/.test(phoneNumber))){ 
							alert("不是完整的11位手机号"); 
							return ;
						}
					}
					openClose = 0;
				}
				$.post(evn_Path+"setting!saveSchedule.do",{deviceId:advancedDeviceId,
															isOpen:openClose,
															idType:idType,
															scheduleType:scheduleType,
															executeTime:executeTime,
															phoneNumber:phoneNumber,
															repeatType:repeatType.length>0?repeatType:"-1"
															},
						function(data){
							if(data=='success'){
								if(scheduleType == 1){
									$("#setting_device_schedule").load(evn_Path+"setting!settingAdvancedDeviceSchedule.do?deviceId="+advancedDeviceId+"&idType="+idType);
							  		$(".setting_advanced_device_right").load(evn_Path+"setting!settingAdvancedDeviceScheduleTime.do");
						  		}else if(scheduleType == 2){
						  			$(".setting_advanced_right").load(evn_Path+"setting!settingAdvancedMonitor.do");
						  		}
							}
						})
				
			}
  	  	}

  	  function phoneNumberRest(upDown){
		if(upDown == 'down'){
			$(".schedule_add_reset").css("background-image","url('"+evn_Path+"resource/device_button_press.png')");
		}else if(upDown == 'up'){
			$(".schedule_add_reset").css("background-image","url('"+evn_Path+"resource/device_button.png')");
			$(".setting_advanced_device_right").load(evn_Path+"setting!settingAdvancedDeviceScheduleTime.do");
		}
		
	}
  	</script>
  	
  </head>
  
  <body>
		<div class="schedule_open_close" id="schedule_open_close_button">
			<div class="schedule_open" onclick="scheduleOpenClose('1')">开</div>
			<div class="schedule_close" onclick="scheduleOpenClose('0')">关</div>
		</div>
		<div class="schedule_open_close" id="schedule_open_close_phone" style="line-height: 60px;">
			<span style="margin-left: 10px;font-size: 16px;font-weight: bold;">手机号码</span>
			<input type="text" name="phoneNumber" id="phoneNumber" onclick="callVK();" style="height: 25px;width: 150px;"/>
		</div>
		<div  class="schedule_repeat_text">
			重复
		</div>
		<div class="schedule_week_all">
			<div class="schedule_week_item" id="schedule_week_item1" onclick="pressWeek('1')" isSelect="0" weekId="1">
				周一
			</div>
			<div class="schedule_week_item" id="schedule_week_item2" onclick="pressWeek('2')" isSelect="0" weekId="2">
				周二
			</div>
			<div class="schedule_week_item" id="schedule_week_item3" onclick="pressWeek('3')" isSelect="0" weekId="3">
				周三
			</div>
			<div class="schedule_week_item" id="schedule_week_item4" onclick="pressWeek('4')" isSelect="0" weekId="4">
				周四
			</div>
			<div class="schedule_week_item" id="schedule_week_item5" onclick="pressWeek('5')" isSelect="0" weekId="5">
				周五
			</div>
			<div class="schedule_week_item" id="schedule_week_item6" onclick="pressWeek('6')" isSelect="0" weekId="6">
				周六
			</div>
			<div class="schedule_week_item" id="schedule_week_item7" onclick="pressWeek('7')" isSelect="0" weekId="7">
				周日
			</div>
		</div>
		<div class="schedule_time">
			<div class="schedule_time_year">
				<span>年份</span>
				<div class="schedule_time_up" onmousedown="pressTimeUpDown('up','1','down')" onmouseup="pressTimeUpDown('up','1','up')"></div>
				<div class="schedule_time_text" id="schedule_time_text_year">2011</div>
				<div class="schedule_time_down" onmousedown="pressTimeUpDown('down','1','down')" onmouseup="pressTimeUpDown('down','1','up')"></div>
			</div>
			<div class="schedule_time_month">
				<span>月份</span>
				<div class="schedule_time_up" onmousedown="pressTimeUpDown('up','2','down')" onmouseup="pressTimeUpDown('up','2','up')"></div>
				<div class="schedule_time_text" id="schedule_time_text_month">3</div>
				<div class="schedule_time_down" onmousedown="pressTimeUpDown('down','2','down')" onmouseup="pressTimeUpDown('down','2','up')"></div>
			</div>
			<div class="schedule_time_day">
				<span>日数</span>
				<div class="schedule_time_up" onmousedown="pressTimeUpDown('up','3','down')" onmouseup="pressTimeUpDown('up','3','up')"></div>
				<div class="schedule_time_text" id="schedule_time_text_day">21</div>
				<div class="schedule_time_down" onmousedown="pressTimeUpDown('down','3','down')" onmouseup="pressTimeUpDown('down','3','up')"></div>
			</div>
			<div class="schedule_time_hour">
				<span>小时</span>
				<div class="schedule_time_up" onmousedown="pressTimeUpDown('up','4','down')" onmouseup="pressTimeUpDown('up','4','up')"></div>
				<div class="schedule_time_text" id="schedule_time_text_hour">12</div>
				<div class="schedule_time_down" onmousedown="pressTimeUpDown('down','4','down')" onmouseup="pressTimeUpDown('down','4','up')"></div>
			</div>
			<div class="schedule_time_minites">
				<span>分钟</span>
				<div class="schedule_time_up" onmousedown="pressTimeUpDown('up','5','down')" onmouseup="pressTimeUpDown('up','5','up')"></div>
				<div class="schedule_time_text" id="schedule_time_text_minites">15</div>
				<div class="schedule_time_down" onmousedown="pressTimeUpDown('down','5','down')" onmouseup="pressTimeUpDown('down','5','up')"></div>
			</div>
		</div>
		<div class="schedule_add">
			<div class="schedule_add_button" onmousedown="pressTimeAdd('down')" onmouseup="pressTimeAdd('up')">增加</div>
			<div class="schedule_add_reset" onmousedown="phoneNumberRest('down')" onmouseup="phoneNumberRest('up')">重置</div>
		</div>  	
  </body>
</html>
